package com.mune.gulimall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

public class Cart {
  private List<CartItem> items;
  private Integer countNum; // 商品数量
  private Integer countType; // 商品种类数量
  private BigDecimal totalAmount; // 总价
  private BigDecimal reduce = new BigDecimal("0.00"); // 减免价格

  public List<CartItem> getItems() {
    return items;
  }

  public void setItems(List<CartItem> items) {
    this.items = items;
  }

  public Integer getCountNum() {
    this.countNum = 0;
    if (this.items != null && this.items.size() > 0) {
      for (CartItem item : this.items) {
        this.countNum += item.getCount();
      }
    }
    return this.countNum;
  }

  public Integer getCountType() {
    this.countType = 0;
    if (this.items != null && this.items.size() > 0) {
      for (int i = 0, len = this.items.size(); i < len; i++) {
        this.countType += 1;
      }
    }
    return this.countType;
  }

  public BigDecimal getTotalAmount() {
    this.totalAmount = new BigDecimal("0");
    if (this.items != null && this.items.size() > 0) {
      for (CartItem item : this.items) {
        if (item.getCheck()) {
          this.totalAmount = this.totalAmount.add(item.getTotalPrice());
        }
      }
    }
    this.totalAmount = this.totalAmount.subtract(this.getReduce());
    return this.totalAmount;
  }

  public BigDecimal getReduce() {
    return reduce;
  }

  public void setReduce(BigDecimal reduce) {
    this.reduce = reduce;
  }
}
